<!--
	Carnegie Mellon University
	School of Computer Science
	MSIT eBusiness Technology

	Team 8 - Infinity (2011 Spring)
	infinity-team8@googlegroups.com

	Professor: Jeffrey L. Eppinger
	Program Faculty: Sujata Telang
-->

<jsp:include page="customer-template-top.jsp" />
<jsp:include page="customer-topnav.jsp" />
<%@ page import="databean.CustomerBean" %>
<%@ page import="model.CustomerDAO" %>
<%@ page import="model.PositionDAO" %>
<%
	CustomerBean customer = (CustomerBean) session.getAttribute("customer");
%>

<%@ page import="databean.FundBean" %>

<div id="header">
	<h1>Buy Fund</h1>
</div>
<jsp:include page="customer-sidebar.jsp" />

<div id="content">

<div id="form-wrapper">
<jsp:include page="customer-error-list.jsp" />
	<form method="post" action="customer-buy-fund.do">
	<div class="box">
	<%
		CustomerDAO customerDAO = new CustomerDAO();
		PositionDAO positionDAO = new PositionDAO();
	%>
	 Available Cash <span style="font-style:italic;font-weight:normal;">$<%=customerDAO.getAvailableCashFormatted(customer.getUserName())%></span>
	</div>
	<div class="line-wrap">
		<label>Fund Symbol</label>
		<div class="field">
			<select style="margin-left:-250px" name="fundID">
				<%
					FundBean[] funds = (FundBean[]) request.getAttribute("fundList");							
					for (FundBean fund : funds) {
						String ownedShares = "";
						if (positionDAO.lookup(customer.getCustomerID(), fund.getFundID()) != null) {
							ownedShares = "(owned shares: " + positionDAO.getAvailableSharesFormatted(customer.getCustomerID(), fund.getFundID()) + ")";
						}
				%>
					<option value="<%=fund.getFundID()%>"><%=fund.getSymbol()%> <%=ownedShares%></option>
				<%
					}
				%>
			</select>
		</div>
	</div>
	<div class="line-wrap">
		<label>Amount  </label>
		<div class="field"><input class="medium" style="margin-left:-250px" type="text" name="amount" value=""/></div>
	</div>
	<div class="button"><input type="submit" name="button" value="Buy"/></div>
	</form>
</div>
</div>
<jsp:include page="footer.jsp" />
